<template>
  <div class="top-menu">
    <el-menu :default-active="activeIndex" mode="horizontal" text-color="#333">
      <el-menu-item v-for="(item, index) in items" :index="item.id" @click.native="openMenu(item)" :key="index">
        <template slot="title">
          <i :class="item.icon"></i>
          <span>{{ generateTitle(item) }}</span>
        </template>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'TopMenu',
  data () {
    return {
      activeIndex: '0',
      items: []
    }
  },
  inject: ['index'],
  created () {
    this.getMenu()
  },
  computed: {
    ...mapGetters(['tagCurrent', 'menu'])
  },
  methods: {
    openMenu (item) {
      this.index.openMenu(item)
    },
    getMenu () {
      // this.$store.dispatch('GetTopMenu').then(res => {
      //   this.openMenu(res[0])
      //   this.items = res
      // })
    },
    generateTitle (item) {
      return this.$router.$avueRouter.generateTitle(item)
    }
  }
}
</script>
